package com.buer.train.common.handle;


import com.buer.train.common.eumn.ResultEnum;
import com.buer.train.common.utils.BaseResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 *
 * @ProjectName:
 * @Package:        com.buer.train.common.handle
 * @ClassName:      BaseExceptionHandler
 * @Description:    java类作用描述
 * @Author:         lds
 * @CreateDate:     2021/1/14 17:25
 * @UpdateUser:     更新者
 * @UpdateDate:     2021/1/14 17:25
 * @UpdateRemark:   更新内容
 * @Version:        1.0
 */
@ControllerAdvice
public class BaseExceptionHandler {
    @ResponseBody
    @ExceptionHandler({BaseError.class,Exception.class})
    public BaseResult dealException(Exception e){
        e.printStackTrace();
        System.out.println(e.getMessage());
        if(e instanceof BaseError) {
            BaseError baseError = (BaseError) e;
            return BaseResult.build(baseError.getErrorCode(),baseError.getErrorMsg(),null);
        }else {
            return BaseResult.build(ResultEnum.SERVER_ERROR,null);
        }

    }
}
